package com.study.demo_thymeleaf.controller;

import com.study.demo_thymeleaf.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @ClassName: UserController
 * @Description:
 * @author: WS
 * @date 2020/12/9
 * @Version: 1.0
 **/
@Controller
public class UserController {
    @GetMapping("/user")
    public String user(Model model){
        List<User> users=new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user=new User();
            Random random=new Random();
            user.setId(Long.valueOf(i));
            user.setGender(random.nextInt(3));
            user.setName("name-->"+i);
            user.setAddress("address-->"+i);
            users.add(user);
        }
        model.addAttribute("users",users);
        return "users";
    }
}
